package com.world.lzh.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;

/**
 * @version 1.0
 * @Author lzh
 * @Date 2022/4/26 - 21:42
 * @Description 自定义拦截器
 **/
@Component
public class CommonInterceptor implements HandlerInterceptor {

    //处理请求之前执行
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.err.println("请求ip："+request.getRemoteAddr());
        System.err.println("请求的方法："+request.getMethod());
        return true;
    }

    //处理请求之后执行
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("postHandle----请求之后执行");
    }

    //响应后执行
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("afterCompletion----响应之后执行");
    }
}
